package com.central.user.controller;

import com.central.model.common.PageResult;
import com.central.model.common.Result;
import com.central.user.model.AccountInfo;
import com.central.user.model.BlackListInfo;
import com.central.user.service.PlayerListServiceI;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.*;

//玩家名单管理
@RestController
public class PlayerListController {

    @Autowired
    private PlayerListServiceI playerListService;

    @PreAuthorize("hasAuthority('operation:get/playerList/getBlackListAll')")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")})
    @GetMapping("/playerList/getBlackListAll")
    public PageResult<BlackListInfo> getBlackListAll(@RequestParam Map<String, Object> params){
        return playerListService.getBlackListAll(params);
    }

    @PreAuthorize("hasAuthority('operation:get/playerList/getPlayerAll')")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")})
    @GetMapping("/playerList/getPlayerAll")
    public PageResult<AccountInfo> getPlayerAll(@RequestParam Map<String, Object> params){
        System.out.println(params);
        return playerListService.getPlayerAll(params);
    }

    @PreAuthorize("hasAuthority('operation:get/playerList/kickPlayer')")
    @GetMapping("/playerList/kickPlayer")
    public Result kickPlayer(@RequestParam Long id){
        return playerListService.kickPlayer("kick",id);
    }

    @PreAuthorize("hasAuthority('operation:get/playerList/addOrRemoveBlackList')")
    @GetMapping("/playerList/addBlackList")
    public Result addOrRemoveBlackList(@RequestParam Long playerId){
        boolean freeze = true;
        return playerListService.addOrRemoveBlackList("freeze",playerId,freeze);
    }


}
